{
  Базовые определения параметров конфигурации

 TcfgParmInfo - Информация о конфигурационном параметре модуля
 TcfgParmtr - Значение конфигурационного параметра
 TcfgSection - Раздел конфигурации

   версия 0.1 март 2011 prodg@ya.ru D.Kondakov
}
unit IIntgrlBaseParms;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, IIntgrlTypes;

{$i calcconfig.inc}

type
  TParametrType = (pText, pLogic, pNumber, pFloat, pFile, pPath, pURL, pIP, pDB, pUSER);
  TParamValueSrc = (pvCmdLine, pvEnvnmnt, pvCfgFile);

  PcfgParmtrInfo = ^TcfgParmtrInfo;
  TcfgParmtrInfo = record
    prmName: TinlNameType;
    prmValue: TParametrType;
    prmCaption: TinlStringType;
    prmComment: TinlStringType;
    DefValue: TinlStringType;
    ChkValue: TinlLogicType;
    prmMngbl: TinlLogicType;
  end;

  TcfgSection = class;

  { TcfgParmtr }

  TcfgParmtr = class
    constructor Create(aSectn: TcfgSection; aName: TinlNameType; aVal: TinlStringType);
    destructor Destroy; override;
  private
    FParamInfo: PcfgParmtrInfo;
    FParamSectn: TcfgSection;
    FParamCfgName: TinlNameType;
    FParamValue: TinlStringType;
    FValueSrc: TParamValueSrc;
    FOldValue: TinlStringType;
    function GetChenged: TinlLogicType;
    function GetParamCaption: TinlStringType;
    function GetParamComment: TinlStringType;
    function GetDefValue: TinlStringType;
    function GetChanged: TinlLogicType;
  protected
    function GetStringVal: TinlStringType; virtual;
    procedure SetStringVal(const sVal: TinlStringType); virtual;
    function CheckStringVal(const sVal: TinlStringType): TinlLogicType; virtual;
    property prmInfo: PcfgParmtrInfo read FParamInfo;
    property ValueSrc: TParamValueSrc read FValueSrc;
  public
    property prmAsStr: TinlStringType read GetStringVal write SetStringVal;
    property prmCaption: TinlStringType read GetParamCaption;
    property prmComment: TinlStringType read GetParamComment;
    property prmChanged: TinlLogicType read GetChenged;
    property OldValue: TinlStringType read FOldValue;
    property DefValue: TinlStringType read GetDefValue;
  end;


  { TcfgSection }

  TcfgSection = class
    constructor Create(aName: TinlNameType);
    destructor Destroy; override;
    procedure AddSubsctn(scnName: TinlNameType);
    procedure AddPrmtr(pInfo: PcfgParmtrInfo);
  private
    FSectnName: TinlNameType;
    FParams: TStringList;
    function GetParams(paramID: TinlID): TcfgParmtr;
    procedure SetParams(paramID: TinlID; const AValue: TcfgParmtr);
  public
    property SectnName: TinlNameType read FSectnName;
    property Params[paramID: TinlID]: TcfgParmtr read GetParams write SetParams; default;
  end;

  { TcfgTree }

  TcfgTree = class(TcfgSection)
    constructor Create(aName: TinlNameType);
    destructor Destroy; override;
  end;

resourcestring
  cfgValDelim = '=';
  cfgPrmDelim = '_';
  cfgSecDelim = '.';

implementation

{ TcfgTree }

constructor TcfgTree.Create(aName: TinlNameType);
begin

end;

destructor TcfgTree.Destroy;
begin
  inherited Destroy;
end;

{ TcfgSection }

constructor TcfgSection.Create(aName: TinlNameType);
begin

end;

destructor TcfgSection.Destroy;
begin
  inherited;
end;

procedure TcfgSection.AddSubsctn(scnName: TinlNameType);
begin
  FSectnName := scnName;
end;

procedure TcfgSection.AddPrmtr(pInfo: PcfgParmtrInfo);
begin

end;

function TcfgSection.GetParams(paramID: TinlID): TcfgParmtr;
begin

end;

procedure TcfgSection.SetParams(paramID: TinlID; const AValue: TcfgParmtr);
begin

end;

{ TcfgParmtr }

constructor TcfgParmtr.Create(aSectn: TcfgSection; aName: TinlNameType; aVal: TinlStringType);
begin
  FParamSectn := aSectn;
  FParamCfgName := aName;
  FParamValue := aVal;
  FOldValue := aVal;
  FParamInfo := nil;
end;

destructor TcfgParmtr.Destroy;
begin
  inherited;
end;

function TcfgParmtr.GetParamCaption: TinlStringType;
begin

end;

function TcfgParmtr.GetChenged: TinlLogicType;
begin

end;

function TcfgParmtr.GetParamComment: TinlStringType;
begin

end;

function TcfgParmtr.GetDefValue: TinlStringType;
begin
  result := FParamInfo^.DefValue;
end;

function TcfgParmtr.GetChanged: TinlLogicType;
begin

end;

function TcfgParmtr.GetStringVal: TinlStringType;
begin
  result := FParamValue;
end;

procedure TcfgParmtr.SetStringVal(const sVal: TinlStringType);
begin
//  if (FParamValue = sVal) or (FCheckValue and not CheckStringVal(sVal)) then exit;
  FOldValue := FParamValue;
  FParamValue := sVal;
end;

function TcfgParmtr.CheckStringVal(const sVal: TinlStringType): TinlLogicType;
begin
  result := true;
end;

end.

